<?php
namespace app\index\controller;

class Member extends Base {
	var $modelDb;
	public function _initialize() {
		parent::_initialize();
		$this->modelDb = model("Member");
	}
	public function index() {

		$this->assign('title', '个人中心');
		return $this->fetch();
	}
	public function member_info() {
		$data = config("IDENTITY");
		$datas = [];
		foreach ($data as $k => $v) {
			$r['id'] = "$k";
			$r['name'] = $v;
			$datas[] = $r;
		}
		$this->assign('datajson', json_encode($datas));
		$this->assign('title', '个人信息');
		return $this->fetch();
	}
	public function editpwd() {
		$this->assign('title', '修改密码');
		return $this->fetch();
	}
	public function personal() {
		$meminfo = model('Member')->get_data(['item_id' => $this->postData['id']]);
		$where['userid'] = $this->postData['id'];
		//下单
		$downlist = model("Requires")->list_data($where);
		$downlists = [];
		foreach ($downlist as $v) {
			$v['nickname'] = $meminfo['nickname'];
			$v['catname'] = $v['catname'];
			$v['avatar'] = $meminfo['avatar'];
			$downlists[] = $v;
		}
		//接单
		$where['status'] = ['neq', 0];
		$picklist = model("Pickorder")->list_data($where);
		$picklists = [];
		foreach ($picklist as $v) {
			$info = model("Requires")->get_data(['item_id' => $v['requiresid']]);
			$memdata = model("Member")->get_data(['item_id' => $info['userid']]);
			$info['nickname'] = $memdata['nickname'];
			$info['avatar'] = $memdata['avatar'];
			$info['starttime'] = $v['starttime'];
			$info['endtime'] = $v['endtime'];
			$picklists[] = $info;
		}
		//信誉展示
		$creinfo = model('MemberCredit')->where('userid', $this->postData['id'])->find();
		$this->assign('creinfo', $creinfo);
		$this->assign('picklists', $picklists);
		$this->assign('downlists', $downlists);
		$this->assign('meminfo', $meminfo);
		$this->assign('title', '个人中心');
		return $this->fetch();
	}
	public function add_poster() {
		$info = model('Poster')->get_data(['item_id' => $this->postData['posterid']]);
		// if ($info['origid'] != 0) {
		// 	$info = model('Poster')->get_data(['item_id'=>$info['origid']]);
		// }
		$this->assign('info', $info);
		$this->assign('title', '编辑海报');
		return $this->fetch();
	}
	public function edit_poster() {
		$info = model('Poster')->get_data(['item_id' => $this->postData['id']]);
		$this->assign('info', $info);
		$this->assign('title', '编辑海报');
		return $this->fetch();
	}
	//余额
	public function amount() {
		$this->assign('title', '我的红豆');
		return $this->fetch();
	}
	public function address() {

		$this->assign('title', '收货地址');
		return $this->fetch();
	}
	public function add_address() {

		$this->assign('title', '添加收货地址');
		return $this->fetch();
	}
	public function edit_address() {
		$info = model('MemberAddress')->get_data(['item_id' => $this->postData['id']]);
		$this->assign('info', $info);
		$this->assign('title', '编辑收货地址');
		return $this->fetch();
	}
	public function choose_address() {
		$this->assign('goods_id', $this->postData['goods_id']);
		$this->assign('title', '选择收货地址');
		return $this->fetch();
	}
	public function exchange_suc() {
		$this->assign('title', '兑换成功');
		return $this->fetch();
	}
	public function share() {
		// $list = model('MemberShare')->list_datas($this->uinfo['userid']);
		// $this->assign('list', $list);
		$this->assign('title', '我的分享');
		return $this->fetch();
	}
	public function share_record() {
		$addday = date("Y-m-d", SYS_TIME);
		$list = model('ShareStat')->where('userid', $this->uinfo['userid'])->where('addday', $addday)->where('typeid', 1)->select();
		$share_poster4 = 0;
		$share_poster5 = 0;
		$share_jifen = 0;
		foreach ($list as $v) {
			if ($v['kind'] == 4) {
				$share_poster4 = $v['nums'];
			}
			if ($v['kind'] == 5) {
				$share_poster5 = $v['nums'];
			}
			if ($v['kind'] == 10) {
				$share_jifen = $v['nums'];
			}
		}
		$this->assign('share_poster4', $share_poster4);
		$this->assign('share_poster5', $share_poster5);
		$this->assign('share_jifen', $share_jifen);
		$this->assign('list', $list);
		$this->assign('title', '分享统计');
		return $this->fetch();
	}
	public function jifen() {

		$this->assign('title', '积分统计');
		return $this->fetch('jifen_record');
	}
	//兑换
	public function exchange() {

		$this->assign('title', '积分兑换');
		return $this->fetch();
	}
	//兑换详情
	public function exchange_detail() {
		$info = model('Convert')->get_data(['item_id' => $this->postData['id']]);
		$this->assign('info', $info);
		$this->assign('title', '兑换详情');
		return $this->fetch();
	}
	public function select_address() {
		$password = db('AdminUser')->where('userid', $this->uinfo['userid'])->value('password');
	}
	//兑换记录
	public function exchange_record() {

		$this->assign('title', '兑换记录');
		return $this->fetch();
	}
	//兑换记录详情
	public function exchange_record_detail() {
		$info = model('OrderConvert')->get_data(['item_id' => $this->postData['oc_id']]);
		$convert = model('Convert')->get_data(['item_id' => $info['convertid']]);
		$this->assign('convert', $convert);
		$this->assign('info', $info);
		$this->assign('title', '兑换记录详情');
		return $this->fetch();
	}
	//积分任务
	public function integral() {
		$this->assign('title', '积分任务');
		return $this->fetch();
	}
	public function chongzhi() {
		$this->assign('title', '充值');
		return $this->fetch();
	}
	public function tixian() {
		$info = model("MemberCard")->where('userid', $this->uinfo['id'])->find();
		if (empty($info)) {
			$info = [
				'cardtype' => 0,
				'province' => 0,
			];
		} else {
			$info['province'] = model("City")->where('title', $info['province'])->value('id');
		}
		$this->assign('info', $info);
		$this->assign('title', '提现');
		return $this->fetch();
	}
	public function evaluate() {
		$info = model('Requires')->get_data(['item_id' => $this->postData['id']]);
		$evasinfo = model('Evas')->where('userid', $this->uinfo['id'])->where('requiresid', $this->postData['id'])->find();
		$isnull = empty($evasinfo) ? 1 : 0;
		$userid = $info['userid'];
		if ($this->postData['typeid'] == 3) {
			$userid = model("Pickorder")->where('requiresid', $this->postData['id'])->where('status', 'gt', 0)->value('userid');
		}
		$this->assign('userid', $userid);
		$this->assign('isnull', $isnull);
		$this->assign('evasinfo', $evasinfo);
		$this->assign('info', $info);
		$this->assign('typeid', $this->postData['typeid']);
		return $this->fetch();
	}
	public function favorites() {
		$list = model("Favorites")->list_data(['userid' => $this->uinfo['id'], 'typeid' => 2]);
		$lists = [];
		foreach ($list as $v) {
			$info = model("Requires")->get_data(['item_id' => $v['contentid']]);
			if (empty($info)) {
				continue;
			}
			$lists[] = $info;
		}
		$this->assign('lists', $lists);
		return $this->fetch();
	}
	public function formwork() {

		$this->assign('title', '我的模板');
		return $this->fetch();
	}

	// 支付页面
	public function pay() {
		$this->assign('title', '支付');
		return $this->fetch();
	}

	// 核销权益界面
	public function hexiaoquanyi() {
		$couponsno = isset($this->postData['code']) ? $this->postData['code'] : '';

		$this->assign('couponsno', $couponsno);
		$this->assign('title', '核销权益');
		return $this->fetch();
	}

	// 会员权益界面
	public function huiyuanquanyi() {
		$this->assign('title', '会员权益');
		return $this->fetch();
	}
	// 会员权益详情界面
	public function yhq_detail() {

		$this->assign('title', '会员权益');
		return $this->fetch();
	}

	// 奖励金列表界面
	public function jianglijinlist() {
		$this->assign('title', '奖励金列表');
		return $this->fetch();
	}

	// 申诉记录界面
	public function shensujilu() {
		$this->assign('title', '申诉记录');
		return $this->fetch();
	}

	// 申诉界面
	public function shensujiemian() {
		$cinfo = model('Client')->where('id', $this->postData['id'])->find();
		$this->assign('cinfo', $cinfo);
		$this->assign('title', '申诉');
		return $this->fetch();
	}

}
